<template>
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="3"
      @filterChange="changeHandle"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      height="auto"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => this.columns = columns"
      :selectionType="'single'"
    >

    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button @click="closeDrawer(2)" type="primary" :disabled='isOpen'>确 定</el-button>
    </div>
  </div>
</template>
<script>
  import {getCentralStorehouse} from '@/api/partsmanage/partWarehouseManage/centralStorehouse/index';
  import { dictionary } from '@/utils/dictMixin';
  export default {
    name: 'selectCentral',
    data(){
      return{
        topFilterList:this.createdFrom(),
        columns:this.createdTable(),
        fetchParams:{
          xtqybz: '',
          xhrAbort: true
        },
        appId:'beijing',
        fetchApi:getCentralStorehouse,
        selectList:[],
        isOpen:true,
      }
    },
    mixins:[dictionary],
    created() {
      this.fetchParams.xtqybz = 10031001
      console.info(this.fetchParams)
    },
    methods:{
      createdFrom(){
        return [
          {
            type: 'INPUT',
            label: '仓库代码',
            fieldName: 'bsckdm',
            placeholder: '请选择',
          },
          {
            type: 'INPUT',
            label: '仓库名称',
            fieldName: 'bsckmc',
            placeholder: '请选择',
          },
        ]
      },
      createdTable(){
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '仓库代码',
            dataIndex: 'bsckdm',
            sorter: true,
            filter: true,
            filterType: 'input',
          },
          {
            title: '仓库名称',
            dataIndex: 'bsckmc',
            sorter: true,
            filter: true,
            filterType: 'input',
          },
        ]
      },
      changeHandle(val){
        this.isOpen=true;
        this.fetchParams=Object.assign({},val)
        this.fetchParams.xtqybz = 10031001
      },
      closeDrawer(type){
        if(type==1){
          this.$emit('close')
        }else{
          let json=this.selectList[0]
          console.info(json)
          this.$emit('close',json)
        }
      },
      selectChangeHandle(val){
        if(val.length>0){
          this.selectList=val;
          this.isOpen=false;
        }else{
          this.isOpen=true;
          this.selectList=[]
        }

      }
    },

  }
</script>
